//
//  UIButton+Extension.swift
//  上海微博
//
//  Created by co on 16/2/26.
//  Copyright © 2016年 王南侠. All rights reserved.
//

import UIKit

extension UIButton{
    
    /**
        创建 UIButton
     
     - parameter title:         title
     - parameter fontSize:      fontSize 默认17
     - parameter color:         color 默认darkGrayColor
     - parameter imageName:     imageName 默认nil
     - parameter backImageName: backImageName 默认nil
     
     - returns: return UIButton
     */
    
    convenience init(cz_title: String?,
        fontSize: CGFloat = 17,
        color: UIColor = UIColor.darkGrayColor(),
        imageName:String? = nil,
        backImageName : String? = nil){
            
            self.init()
            
            self.setTitle(cz_title, forState: .Normal)
            self.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
            self.setTitleColor(color, forState: .Normal)
            
            if let imageName = imageName{
                setImage(UIImage(named: imageName), forState: .Normal)
                setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)

                
            }
            
            if let backImageName = backImageName{
                self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
                self.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)

            }
            
            sizeToFit()
    }
 
}
